package com.dajun.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.dajun.pojo.dto.OperationDto;
import com.dajun.pojo.dto.ProcessQueryDto;
import com.dajun.pojo.dto.ApplyDto;
import com.dajun.result.Result;
import com.dajun.service.FlowableService;
import jdk.jfr.Description;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 流程引擎/测试
 */
@Validated
@Description("流程引擎/测试")
@SaCheckPermission("flowable/text")
@RestController
@RequestMapping("/flowable")
public class FlowableController {

    @Resource
    private FlowableService flowableService;

    /**
     *  开始流程
     * @param dto
     * @return
     */
    @GetMapping("/start")
    public Result start(@Valid @RequestBody ApplyDto dto){
        return flowableService.start(dto);
    }

    /**
     *  终止流程
     */
    @GetMapping("/terminate")
    public Result terminate(@Valid @RequestBody String processInstanceId){
        return flowableService.terminate(processInstanceId);
    }

    /**
     *  获取运行中的流程
     */
    @GetMapping("/select")
    public Result select(@Valid @RequestBody ProcessQueryDto dto){
        return flowableService.select(dto);
    }

    /**
     * 审批节点操作
     */
    @PostMapping("/operation")
    public Result operation(@Valid @RequestBody OperationDto dto){
        return flowableService.operation(dto);
    }

}
